#ifndef SORT_SHELL_HPP
#define SORT_SHELL_HPP

#include "../common.hpp"

YFWZ100_NS_BEGIN

template<typename PointerLike>
static inline
void shell_sort(PointerLike start, PointerLike end, size_t delta)
{
  for (PointerLike i = start + delta; i < end; i ++) {
    PointerLike j = i - delta;
    auto t = *i;
    for (; j >= start && t < *j; j -= delta) {
      *(j + delta) = *j;
    }
    *(j + delta) = t;
  }
}

template <typename PointerLike>
void shell_sort(PointerLike start, PointerLike end)
{
  size_t delta = (end - start ) / 2;
  while (delta >= 1) {
    shell_sort(start, end, delta);
    delta /= 2;
  }
}

YFWZ100_NS_END

#endif//SORT_SHELL_HPP
